﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
 }
 <div class="layuimini-container">
     <div class="layuimini-main">
         <fieldset class="table-search-fieldset layui-hide" id="searchField">
             <div>
                 <form class="layui-form layui-form-pane">
                     <div class="layui-form-item">
                         <div class="layui-inline">
                             <label class="layui-form-label">关键字:</label>
                             <div class="layui-input-inline">
                                 <input type="text" id="txt_keyword" name="txt_keyword" autocomplete="off" class="layui-input">
                             </div>
                         </div>
                         <div class="layui-inline">
                             <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon">&#xe615;</i> 搜 索</button>
                         </div>
                     </div>
                 </form>
             </div>
         </fieldset>
         <script type="text/html" id="toolbarDemo">
             <div class="layui-btn-container">
                 <button id="NF-add" authorize="yes" class="layui-btn layui-btn-sm data-add-btn layui-hide" lay-event="add"><i class="layui-icon">&#xe654;</i>新增</button>
                 <button id="NF-edit" authorize="yes" class="layui-btn layui-btn-sm layui-btn-warm data-edit-btn layui-hide" lay-event="edit"><i class="layui-icon">&#xe642;</i>修改</button>
                 <button id="NF-delete" authorize="yes" class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn layui-hide" lay-event="delete"> <i class="layui-icon">&#xe640;</i>删除</button>
                 <button id="NF-details" authorize="yes" class="layui-btn layui-btn-sm layui-btn-normal data-info-btn layui-hide" lay-event="details"> <i class="layui-icon">&#xe60b;</i>查看</button>
             </div>
         </script>
         <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
         <script type="text/html" id="currentTableBar">
             <a id="NF-edit" authorize="yes" class="layui-btn layui-btn-sm" lay-event="edit">修改</a>
             <a id="NF-delete" authorize="yes" class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete">删除</a>
             <a id="NF-details" authorize="yes" class="layui-btn layui-btn-sm layui-btn-normal data-info-btn" lay-event="details">查看</a>
         </script>
     </div>
 </div>
 <script>
     layui.use(['jquery', 'form', 'common', 'treeTable', 'layer'], function () {
         var $ = layui.jquery,
             form = layui.form,
             layer = layui.layer,
             treeTable = layui.treeTable,
             common = layui.common;
         //行操作权限控制(js是值传递)
         currentTableBar.innerHTML = common.authorizeButtonNew(currentTableBar.innerHTML);
         toolbarDemo.innerHTML = common.authorizeButtonNew(toolbarDemo.innerHTML);
         wcLoading.close();
         var rendertree = common.rendertreetable({
             elem: '#currentTableId',
             url: '/ContentManage/ArticleCategory/GetTreeGridJson',
             tree: {
                 iconIndex: 1,           // 折叠图标显示在第几列
                 isPidData: true,        // 是否是id、pid形式数据
                 idName: 'F_Id',  // id字段名称
                 pidName: 'F_ParentId',     // pid字段名称
                 arrowType: 'arrow2',
                 getIcon: 'ew-tree-icon-style2',
             },
             cols: [[
                 { type: "checkbox", width: 50 },                 
                 //此处需修改
                 { field: 'F_FullName', title: '类别名称', width: 200 },
                 { field: 'F_SortCode', title: '排序', width: 80 },
                 { field: 'F_Description', title: '描述', width: 220 },
                 {
                     field: 'F_EnabledMark', title: '状态', width: 80,
                     templet: function (d) {
                         if (d.F_EnabledMark == true) {
                             return "<span class='layui-btn layui-btn-normal layui-btn-xs'>有效</span>";
                         } else {
                             return "<span class='layui-btn layui-btn-warm layui-btn-xs'>无效</span>";
                         }
                     }
                 }, 
                 {
                     field: 'F_CreatorTime', title: '创建时间', minWidth: 100,
                     templet: function (d) {
                         if (d.F_CreatorTime) {
                             var time = new Date(d.F_CreatorTime);
                             return time.Format("yyyy-MM-dd hh:mm:ss");
                         }
                         return '';
                     }
                 },
                 { field: 'F_CreatorUserId', title: '创建人', width: 120, hide: true },
                 { title: '操作', minWidth: 180, toolbar: '#currentTableBar', align: "center", fixed: 'right' }//插件没有fixed参数
             ]],
             done: function () {
                 //展开全部
                 rendertree.expandAll();
             }
         });
         // 监听搜索操作
         form.on('submit(data-search-btn)', function (data) {
             queryJson = data.field.txt_keyword;
             common.reloadtreetable(rendertree, {
                 where: { keyword: queryJson },
             });
             return false;
         });
         treeTable.on('row(currentTableId)', function (obj) {
             obj.tr.find("div.layui-unselect.layui-form-checkbox")[0].click();
         })
         //toolbar监听事件
         treeTable.on('toolbar(currentTableId)', function (obj) {
             if (obj.event === 'add') {  // 监听添加操作
                 common.modalOpen({
                     title: "添加界面",
                     url: "/ContentManage/ArticleCategory/Form",
                     width: "500px",
                     height: "500px",
                 });
             }
             else if (obj.event === 'delete') {
                 var data = rendertree.checkStatus(false);
                 if (data.length == 0) {
                     common.modalMsg("未选中数据", "warning");
                     return false;
                 }
                 var ids = [];
                 for (var i = 0; i < data.length; i++) {
                     ids.push(data[i].F_Id);
                 }
                 common.deleteForm({
                     url: "/ContentManage/ArticleCategory/DeleteForm",
                     param: { keyValue: ids.join(',') },
                     success: function () {
                         common.reload('data-search-btn');
                     }
                 });
             }
             else if (obj.event === 'edit') {
                 var data = rendertree.checkStatus(false);
                 if (data.length == 0) {
                     common.modalMsg("未选中数据", "warning");
                     return false;
                 }
                 if (data.length > 1) {
                     common.modalMsg("只能选择一条编辑", "warning");
                     return false;
                 }
                 common.modalOpen({
                     title: "编辑界面",
                     url: "/ContentManage/ArticleCategory/Form?keyValue=" + data[0].F_Id,
                     width: "500px",
                     height: "500px",
                     data: data[0],
                 });
             }
             else if (obj.event === 'details') {
                 var data = rendertree.checkStatus(false);
                 if (data.length == 0) {
                     common.modalMsg("未选中数据", "warning");
                     return false;
                 }
                 if (data.length > 1) {
                     common.modalMsg("只能选择一条查看", "warning");
                     return false;
                 }
                 common.modalOpen({
                     title: "查看界面",
                     url: "/ContentManage/ArticleCategory/Details?keyValue=" + data[0].F_Id,
                     width: "500px",
                     height: "500px",
                     data: data[0],
                     btn: []
                 });
             }
             else if (obj.event === 'TABLE_SEARCH') {
                 var _that = $("#searchField");
                 if (_that.hasClass("layui-hide")) {
                     _that.removeClass('layui-hide');
                 } else {
                     _that.addClass('layui-hide');
                 }
             }
             return false;
         });
         //toolbar监听事件
         treeTable.on('tool(currentTableId)', function (obj) {
             if (obj.event === 'delete') {
                 common.deleteForm({
                     url: "/ContentManage/ArticleCategory/DeleteForm",
                     param: { keyValue: obj.data.F_Id },
                     success: function () {
                         obj.del();
                     }
                 });
             }
             else if (obj.event === 'edit') {
                 common.modalOpen({
                     title: "编辑界面",
                     url: "/ContentManage/ArticleCategory/Form?keyValue=" + obj.data.F_Id,
                     width: "500px",
                     height: "500px",
                     data: obj.data,
                 });
             }
             else if (obj.event === 'details') {
                 common.modalOpen({
                     title: "查看界面",
                     url: "/ContentManage/ArticleCategory/Details?keyValue=" + obj.data.F_Id,
                     width: "500px",
                     height: "500px",
                     data: obj.data,
                     btn: []
                 });
             }
             return false;
         });
     });
 </script>
